package com.ruoyi.system.service.impl;

import java.util.List;

import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.framework.web.service.TokenService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.ShelfMapper;
import com.ruoyi.system.domain.Shelf;
import com.ruoyi.system.service.IShelfService;

import javax.servlet.http.HttpServletRequest;

/**
 * 货架Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-10-09
 */
@Service
public class ShelfServiceImpl implements IShelfService 
{
    @Autowired
    private ShelfMapper shelfMapper;
    @Autowired
    private TokenService tokenService;

    /**
     * 查询货架
     * 
     * @param id 货架主键
     * @return 货架
     */
    @Override
    public Shelf selectShelfById(Long id)
    {
        return shelfMapper.selectShelfById(id);
    }

    /**
     * 查询货架列表
     * 
     * @param shelf 货架
     * @return 货架
     */
    @Override
    public List<Shelf> selectShelfList(Shelf shelf)
    {
        return shelfMapper.selectShelfList(shelf);
    }

    /**
     * 新增货架
     * 
     * @param shelf 货架
     * @return 结果
     */
    @Override
    public int insertShelf(HttpServletRequest request, Shelf shelf)
    {
        LoginUser user = tokenService.getLoginUser(request);
        shelf.setCreatorId(user.getUserId());
        shelf.setCreateTime(DateUtils.getNowDate());
        return shelfMapper.insertShelf(shelf);
    }

    /**
     * 修改货架
     * 
     * @param shelf 货架
     * @return 结果
     */
    @Override
    public int updateShelf(Shelf shelf)
    {
        return shelfMapper.updateShelf(shelf);
    }

    /**
     * 批量删除货架
     * 
     * @param ids 需要删除的货架主键
     * @return 结果
     */
    @Override
    public int deleteShelfByIds(Long[] ids)
    {
        return shelfMapper.deleteShelfByIds(ids);
    }

    /**
     * 删除货架信息
     * 
     * @param id 货架主键
     * @return 结果
     */
    @Override
    public int deleteShelfById(Long id)
    {
        return shelfMapper.deleteShelfById(id);
    }
}
